package com.hutao.manage.service.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hutao.manage.constant.Constant;
import com.hutao.manage.mapper.MrInMedicareMapper;
import com.hutao.manage.mapper.MrTransfusionMapper;
import com.hutao.manage.mapper.MrTransfusionObservationMapper;
import com.hutao.manage.mapper.OperativeUserMapper;
import com.hutao.manage.mapper.StdOpDiagHisidMapper;
import com.hutao.manage.mapper.StdOperationMapper;
import com.hutao.manage.mapper.StdPracticingDoctorMapper;
import com.hutao.manage.mapper.StddiseaseClinicMapper;
import com.hutao.manage.mapper.StddiseaseMapper;
import com.hutao.manage.mapper.StdhospitalmanzyMapper;
import com.hutao.manage.mapper.StdhospitalofficeMapper;
import com.hutao.manage.mapper.StdopsoperationClinicMapper;
import com.hutao.manage.mapper.StdopsoperationMapper;
import com.hutao.manage.pojo.MrInMedicare;
import com.hutao.manage.pojo.MrTransfusion;
import com.hutao.manage.pojo.MrTransfusionObservation;
import com.hutao.manage.pojo.OperativeUser;
import com.hutao.manage.pojo.StdDrgChsExclude;
import com.hutao.manage.pojo.StdOpDiagHisid;
import com.hutao.manage.pojo.StdOperation;
import com.hutao.manage.pojo.StdPracticingDoctor;
import com.hutao.manage.pojo.StddiseaseClinic;
import com.hutao.manage.pojo.Stdhospitalmanzy;
import com.hutao.manage.pojo.StdhospitalmanzyExample;
import com.hutao.manage.pojo.StdhospitalmanzyWithBLOBs;
import com.hutao.manage.pojo.Stdhospitaloffice;
import com.hutao.manage.pojo.StdhospitalofficeExample;
import com.hutao.manage.pojo.StdopsoperationClinic;
import com.hutao.manage.service.SyncDataService;
import com.hutao.manage.util.ReadExcelUtil;
import com.hutao.manage.util.StringUtil;

@Service
public class SyncDataServiceImpl implements SyncDataService {
	
	@Autowired
	private MrInMedicareMapper mrInMedicareMapper;

	@Autowired
	private StdopsoperationClinicMapper stdopsoperationClinicMapper;
	
	@Autowired
	private StdopsoperationMapper stdopsoperationMapper;

	@Autowired
	private StddiseaseClinicMapper stddiseaseClinicMapper;
	
	@Autowired
	private StddiseaseMapper stddiseaseMapper;

	@Autowired
	private StdhospitalmanzyMapper stdhospitalmanzyMapper;
	

	@Autowired
	private StdhospitalofficeMapper stdhospitalofficeMapper;
	
	@Autowired
	private OperativeUserMapper operativeUserMapper;
	
	@Autowired
	private StdPracticingDoctorMapper stdPracticingDoctorMapper;
	
	@Autowired
	private StdOperationMapper  stdOperationMapper;
	
	@Autowired
	private MrTransfusionObservationMapper mrTransfusionObservationMapper;
	
	@Autowired
	private MrTransfusionMapper mrTransfusionMapper;
	

	@Override
	public Map<String, Object> syncDisease() {
		Map<String, Object> map = new HashMap<>();
		int count = 1;

		try {

			//List<Map<String, Object>> list = ReadExcel2003_2007.getRecordMapList("D://csdiag.xlsx");
			
			List<Map<String, Object>> list = ReadExcelUtil.readExecl("D://测试库诊断.xlsx");
			StdOpDiagHisid stdOpDiagHisid = null;
			StddiseaseClinic clinic = null;
			map.put("his疾病信息数量", list.size());
			for (Map<String, Object> hisMap : list) {
				clinic = new StddiseaseClinic();
				String hisId = MapUtils.getString(hisMap, "0");
				String diagName = MapUtils.getString(hisMap, "2");
				String diagCode = MapUtils.getString(hisMap, "3");
				
				clinic.setId(Long.valueOf(count));
				clinic.setName(diagName);
				clinic.setClinicCode(diagCode);
				clinic.setHisId(hisId);
				
				stddiseaseClinicMapper.insertStddiseaseClinicHis(clinic);
			
				count++;
				/*
				 * System.out.println(hisId+"--"+diagName+"---"+diagCode);
				 * if(StringUtils.isBlank(diagCode)) { continue; }
				 */
				
				/*
				 * List<Long> ids = stddiseaseClinicMapper.getIdByClinicCode(diagCode);
				 * if(CollectionUtils.isEmpty(ids)) { continue; } for (Long id : ids) {
				 * stddiseaseClinicMapper.updateHisIdById(hisId, id); count++; }
				 */
				
				
				/*
				 * List<StddiseaseClinic> stddiseaseClinicList =
				 * stddiseaseClinicMapper.getStddiseaseClinicByName(diagName); for
				 * (StddiseaseClinic stddiseaseClinic : stddiseaseClinicList) {
				 * stdOpDiagHisidMapper.deleteByParentIdAndType(stddiseaseClinic.getId(), "2");
				 * stdOpDiagHisid = new StdOpDiagHisid();
				 * stdOpDiagHisid.setParentId(stddiseaseClinic.getId());
				 * stdOpDiagHisid.setHisCodeId(Long.valueOf(hisId));
				 * stdOpDiagHisid.setType("2");
				 * stdOpDiagHisidMapper.insertSelective(stdOpDiagHisid); }
				 */

			}
			map.put("疾病信息对应数量", count);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}

	@Override
	public Map<String, Object> syncOps() {
		Map<String, Object> map = new HashMap<>();
		int count = 0;
		try {
			List<Map<String, Object>> list = ReadExcelUtil.readExecl("D://测试库手术字典.xlsx");
			map.put("his手术信息数量", list.size());
			
			StdOpDiagHisid stdOpDiagHisid = null;
			
			List<String> hisOpidList = new ArrayList<>();
			//重复信息:[29666, 49338, 69008]
			for (Map<String, Object> hisMap : list) {
				String hisOpid = MapUtils.getString(hisMap, "0");
				String opCode = MapUtils.getString(hisMap, "1");
				String opName = MapUtils.getString(hisMap, "2");
				
				System.out.println(hisOpid+"-"+opCode+"-"+opName);
				
				List<StdopsoperationClinic> stdopsoperationClinicList = stdopsoperationClinicMapper.getStdopsoperationClinicByName(opName);
				if(CollectionUtils.isNotEmpty(stdopsoperationClinicList)) {
					
					
					for (StdopsoperationClinic stdopsoperationClinic : stdopsoperationClinicList) {
						stdopsoperationClinic.setHisId(hisOpid);
//						stdOpDiagHisidMapper.deleteByParentIdAndType(stdopsoperationClinic.getId(), "1");
//						stdOpDiagHisid = new StdOpDiagHisid();
//						stdOpDiagHisid.setParentId(stdopsoperationClinic.getId());
//						stdOpDiagHisid.setHisCodeId(Long.valueOf(hisOpid));
//						stdOpDiagHisid.setType("1");
//						stdOpDiagHisidMapper.insertSelective(stdOpDiagHisid);
						stdopsoperationClinicMapper.updateHisIdById(hisOpid, stdopsoperationClinic.getId());
					}
					
					
					count++;
				}
				
				
				
				/*
				 * StdopsoperationClinicExample example = new StdopsoperationClinicExample();
				 * StdopsoperationClinicExample.Criteria criteria = example.createCriteria();
				 * criteria.andNameEqualTo(opName);
				 * 
				 * List<StdopsoperationClinic> opsList =
				 * stdopsoperationClinicMapper.selectByExample(example);
				 */
				
			
				
				/*
				 * StdopsoperationWithBLOBs stdopsoperation = null; if
				 * (CollectionUtils.isNotEmpty(opsList)) { for (StdopsoperationClinic
				 * stdopsoperationClinic : opsList) { Long stdopsoperationId =
				 * stdopsoperationClinic.getParentId(); if(stdopsoperationId!=null) {
				 * stdopsoperation =
				 * stdopsoperationMapper.selectByPrimaryKey(stdopsoperationId);
				 * if(stdopsoperation!=null) { stdopsoperation.setRfrcodeNinth(hisOpid);
				 * stdopsoperationMapper.updateByPrimaryKeySelective(stdopsoperation); count++;
				 * } }
				 * 
				 * }
				 * 
				 * }
				 */

			}
			System.out.println("重复信息:"+hisOpidList);
			
			map.put("手术信息对应数量", count);
		} catch (IOException e) {

			e.printStackTrace();
		}
		return map;
	}

	@Override
	public Map<String, Object> syncHospitalMan() {
		Map<String, Object> map = new HashMap<>();
		int totalCount = 0;

		try {

			Map<String,String> hisIdMap = this.getHospitalManHisId();
		
			
			
			List<Map<String,Object>> manMapList = stdhospitalmanzyMapper.getNoHisIdList();
			
			
			for (Map<String, Object> map2 : manMapList) {
				String jobNumber = MapUtils.getString(map2, "JOB_NUMBER");
				Long id =  MapUtils.getLong(map2, "ID");
				 String hisId = MapUtils.getString(hisIdMap,jobNumber);
				 if(StringUtils.isNotEmpty(hisId)) {
					 totalCount++;
					 System.out.println(jobNumber+"--"+hisId);
					 stdhospitalmanzyMapper.updateSwitchCodeJByPrimaryKey(id, hisId.trim());
				 }
				 
				
			}

			
			map.put("人员信息对应数量", totalCount);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}
	
	
	@Override
	public Map<String, Object> syncOfficeBySwitchCodeb() {
		Map<String, Object> map = new HashMap<>();
		int count = 0;
		int totalCount = 0;

		try {

			List<Map<String, Object>> list = ReadExcelUtil.readExecl("D://给手麻用科室.xlsx");

			map.put("his科室数量", list.size());
			for (Map<String, Object> hisMap : list) {
				String id = MapUtils.getString(hisMap, "0");
				String officeSwitchCode = MapUtils.getString(hisMap, "1");
				String officeName = MapUtils.getString(hisMap, "2");
				
				System.out.println(id+"-"+officeSwitchCode+"-"+officeName);

				if (StringUtils.isEmpty(officeSwitchCode)) {
					continue;
				}
				
				
				

				List<Stdhospitaloffice> officeList = stdhospitalofficeMapper.selectBySwitchCodeb(officeSwitchCode.toUpperCase());
				if (CollectionUtils.isNotEmpty(officeList)) {
					for (Stdhospitaloffice office : officeList) {
						office.setSwitchCodeJ(id);
						stdhospitalofficeMapper.updateByPrimaryKeySelective(office);
						count++;
					}
				}

			}
			map.put("科室对应数量", count);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}


	@Override
	public Map<String, Object> syncOfficeByName() {
		Map<String, Object> map = new HashMap<>();
		int count = 0;
		int totalCount = 0;

		try {

			List<Map<String, Object>> list = ReadExcelUtil.readExecl("D://给手麻用科室.xlsx");

			map.put("his科室数量", list.size());
			for (Map<String, Object> hisMap : list) {
				String id = MapUtils.getString(hisMap, "0");
				String officeSwitchCode = MapUtils.getString(hisMap, "1");
				String officeName = MapUtils.getString(hisMap, "2");
				
				System.out.println(id+"-"+officeSwitchCode+"-"+officeName);

				if (StringUtils.isEmpty(officeName)) {
					continue;
				}
				
				 if (!officeName.contains("-")) {
				  
					 continue;
				 }
				 
				
				StdhospitalofficeExample example = new StdhospitalofficeExample();
				StdhospitalofficeExample.Criteria criteria = example.createCriteria();
				criteria.andSwitchCodeBEqualTo(officeSwitchCode);
				//criteria.andNameEqualTo(officeName.split("-")[1]);
				criteria.andOrgcodeEqualTo("49557184-0");

				List<Stdhospitaloffice> officeList = stdhospitalofficeMapper.selectByExample(example);
				if (CollectionUtils.isNotEmpty(officeList)) {
					for (Stdhospitaloffice office : officeList) {
						office.setSwitchCodeJ(id);
						stdhospitalofficeMapper.updateByPrimaryKeySelective(office);
						count++;
					}
				}

			}
			map.put("科室对应数量", count);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}

	@Override
	public String syncDataService() {
		int count = 0;
		StdhospitalmanzyExample example = new StdhospitalmanzyExample();
		StdhospitalmanzyExample.Criteria criteria = example.createCriteria();
		criteria.andOrgcodeEqualTo("49557184-0");
		List<Stdhospitalmanzy> hospitalManList = stdhospitalmanzyMapper.selectByExample(example);
		OperativeUser operativeUser = null;
		for (Stdhospitalmanzy stdhospitalmanzy : hospitalManList) {
			if(StringUtils.isEmpty(stdhospitalmanzy.getJobNumber())) {
				continue;
			}
			
			String officeCode = stdhospitalmanzyMapper.getManOfficeCodeById(stdhospitalmanzy.getParentid());
			
			operativeUser = new OperativeUser();
			operativeUser.setIdCard(stdhospitalmanzy.getIdcard());
			operativeUser.setName(stdhospitalmanzy.getName());
			operativeUser.setOrganization("山东省立医院");
			operativeUser.setOrganizationId(stdhospitalmanzy.getOrgcode());
			operativeUser.setDeptCode(officeCode);
			
			operativeUser.setUserName(stdhospitalmanzy.getJobNumber());
			operativeUser.setPassword("123456@slyy");
			if(StringUtils.isNotBlank(officeCode)) {
				operativeUser.setDeptName(getDeptNameByCode(officeCode));
			}
			operativeUser.setRecordTime(new Date());
			operativeUserMapper.insertSelective(operativeUser);
			count++;
		}
		return count+"";
	}
	
	public String getDeptNameByCode(String officeCode) {
		if(StringUtils.isEmpty(officeCode)) {
			return "";
		}
		StdhospitalofficeExample example = new StdhospitalofficeExample();
		StdhospitalofficeExample.Criteria criteria = example.createCriteria();
		criteria.andOrgcodeEqualTo("49557184-0");
		criteria.andCodeEqualTo(officeCode);
		List<Stdhospitaloffice> officeList = stdhospitalofficeMapper.selectByExample(example);
		if(CollectionUtils.isNotEmpty(officeList)) {
			return officeList.get(0).getCode()+"-"+officeList.get(0).getName();
		}
		
		return null;
	}

	//@TargetDataSource(name="ds2")
	@Override
	public String addStdPracticingDoctor() {
		List<StdPracticingDoctor> practicingDoctors = new ArrayList<StdPracticingDoctor>();
		try {
			List<Map<String, Object>> list = ReadExcelUtil.readExecl("D://执业医师编码.xls");
			StdPracticingDoctor stdPracticingDoctor = null;
			for (Map<String, Object> map : list) {
				//System.out.println(map);
				stdPracticingDoctor = new StdPracticingDoctor();
				stdPracticingDoctor.setName(MapUtils.getString(map, "0"));
				stdPracticingDoctor.setSex(MapUtils.getString(map, "2"));
				stdPracticingDoctor.setIdCard(MapUtils.getString(map, "1"));
				stdPracticingDoctor.setPracticeStatus(MapUtils.getString(map, "10"));
				stdPracticingDoctor.setRegisterStatus(MapUtils.getString(map, "7"));
				stdPracticingDoctor.setCertificatePractice(MapUtils.getString(map, "8"));
				stdPracticingDoctor.setTechCompetent(MapUtils.getString(map, "5"));
				stdPracticingDoctor.setEducatione(MapUtils.getString(map, "11"));
				stdPracticingDoctor.setWorkOffice(MapUtils.getString(map, "12"));
				stdPracticingDoctor.setType(1);
				//1=董雁, 2=女, 3=370882199409080820, 4=34585, 5=26, 6=在册, 7=变更注册, 8=201937002633, 9=45342.4281128819, 10=护士, 11=大学专科, 12=病房
				practicingDoctors.add(stdPracticingDoctor);
			}
			
			for (StdPracticingDoctor obj : practicingDoctors) {
				System.out.println(obj);
				stdPracticingDoctorMapper.insertSelective(obj);
			}
		} catch (IOException e) {
		
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public String addStdOperation() {
		int count = 0;
		try {
			List<Map<String, Object>> list = ReadExcelUtil.readExecl("D://op.xlsx");
			StdOperation stdOperation = null;
			for (Map<String, Object> map : list) {
				stdOperation = new StdOperation();
				stdOperation.setCode(MapUtils.getString(map, "0"));
				stdOperation.setName(MapUtils.getString(map, "1"));
				String operationMarkName = MapUtils.getString(map, "2");
				String operationMarkCode = null;
				if(StringUtils.isNotBlank(operationMarkName)) {
					if("诊断性操作".equals(operationMarkName)) {
						operationMarkCode = "DP";
					}else if("手术".equals(operationMarkName)) {
						operationMarkCode = "SS";
					}else if("治疗性操作".equals(operationMarkName)) {
						operationMarkCode = "TP";
					}
				}
				stdOperation.setOperationMarkCode(operationMarkCode);
				stdOperation.setOperationMarkName(operationMarkName);
				
				String operationLevelName = MapUtils.getString(map, "3");
				String operationLevelCode = null;
				if(StringUtils.isNotBlank(operationLevelName)) {
					if("四级".equals(operationLevelName)) {
						operationLevelCode = "4";
					}else if("三级".equals(operationLevelName)) {
						operationLevelCode = "3";
					}else if("二级".equals(operationLevelName)) {
						operationLevelCode = "2";
					}else if("一级".equals(operationLevelName)) {
						operationLevelCode = "1";
					}
				}
				stdOperation.setOperationLevelCode(operationLevelCode);
				stdOperation.setOperationLevelName(operationLevelName);
				stdOperation.setComment(MapUtils.getString(map, "4"));
				stdOperation.setStatus(1);
				stdOperationMapper.insertSelective(stdOperation);
				count++;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "保存成功手术信息数量为:"+count;
	}

	@Override
	public String addStdDrgChsExclude() {
		StdDrgChsExclude stdDrgChsExclude = null;
		int totalCount = 0;
		for (int i = 1; i <= 202; i++) {
			stdDrgChsExclude = new StdDrgChsExclude();
			stdDrgChsExclude.setCode(Integer.toString(i));
			stdDrgChsExclude.setName("表7-"+i);
			stdDrgChsExclude.setIndexcode("B7-"+i);
			if(operativeUserMapper.insertStdDrgChsExclude(stdDrgChsExclude)>0) {
				totalCount++;
			} ;
		}
		
		
		return "添加数据条数:"+totalCount;
	}
	
	

	@Transactional
	@Override
	public String addMrInMedicareByExcel() {
		List<Map<String, Object>> list =  null;
		int count = 0;
		try {
			list = ReadExcelUtil.readExecl("D://医保数据.xlsx");
			//{0=*99000720083168615395, 1=2020/8/31, 2=10:54:44, 3=null, 4=6580746, 5=10993917, 6=省医保B(异地), 7=2020/8/31, 8=22617347}
			MrInMedicare mrInMedicare = null;
			
			Map<String,Integer> icuHourMap = generateIcuHourMap();
			
			Map<String,Map<String,Float>> hxjmxMap =  generateHxjmxMap();
			
			for (Map<String, Object> map : list) {
				String patientId = MapUtils.getString(map, "8");
				mrInMedicare = new MrInMedicare();
				mrInMedicare.setAccountnumber(MapUtils.getString(map, "0"));
				mrInMedicare.setAccountdate(MapUtils.getString(map, "1"));
				mrInMedicare.setAccounttime(MapUtils.getString(map, "2"));
				mrInMedicare.setAccountcard(MapUtils.getString(map, "3"));
				mrInMedicare.setMrId(MapUtils.getString(map, "4"));
				mrInMedicare.setOnlyId(MapUtils.getString(map, "5"));
				mrInMedicare.setType(MapUtils.getString(map, "6"));
				mrInMedicare.setOuttime(MapUtils.getString(map, "7"));
				mrInMedicare.setOrganizationId("49557184-0");
				if(StringUtils.isNotBlank(patientId)) {
					Integer icuHour = MapUtils.getInteger(icuHourMap, patientId);
					if(icuHour!=null) {
						mrInMedicare.setIcu("是");
						mrInMedicare.setIcutime(icuHour.longValue());
					}
					
					Map<String,Float> hxjMap = MapUtils.getMap(hxjmxMap, patientId);
					if(hxjMap!=null) {
						for (Map.Entry<String, Float> m : hxjMap.entrySet()) {
							String mxCode = m.getKey();
							Float mxValue = m.getValue();
							if("呼吸机辅助呼吸".equals(mxCode)) {
								mrInMedicare.setVentilator(mxValue);
							}else {
								mrInMedicare.setInvasivev(mxValue);
							}
						}
					}
					
					
				}
				
				
				/*
				 * if(mrInMedicareMapper.insert(mrInMedicare)>0) { count++;
				 * System.out.println("数据总条数为:"+list.size()+",当前保存数据为第"+count+"条！"); }
				 */
				
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "医保数据Excel中数据总数为:"+list.size()+",保存到数据库成功条数为:"+count;
	}
	
	
	private static Map<String,Integer> generateIcuHourMap() throws IOException{
		//根据excel获取icu时间和patientId
		List<Map<String, Object>> list = ReadExcelUtil.readExecl("D://icu.xlsx");
		Map<String,Integer> icuTypeMap = new HashMap<>();
		for (Map<String, Object> map : list) {
			//patientId
			String patientId = MapUtils.getString(map, "0");
			//ICU时间
			Integer icuHours = MapUtils.getInteger(map, "4");
			if(icuTypeMap.get(patientId)==null) {
				icuTypeMap.put(patientId, icuHours);
			}else {
				System.out.println(patientId);
				Integer oldIcuHour =  MapUtils.getInteger(icuTypeMap, patientId);
				icuTypeMap.put(patientId, oldIcuHour+icuHours);
			}
		}
		System.out.println(icuTypeMap);
		System.out.println(icuTypeMap.size());
		
		return icuTypeMap;
	}
	
	
	private static Map<String,Map<String,Float>> generateHxjmxMap() throws IOException{
		List<Map<String, Object>> list = ReadExcelUtil.readExecl("D://呼吸机明细.xlsx");
		System.out.println(list.size());
		Map<String,Map<String,Float>> respiratorMap = new HashMap<>();
		
		for (Map<String, Object> map : list) {
			String patientId = MapUtils.getString(map, "1");
			String itemCode = MapUtils.getString(map, "5");
			Float itemQuailty = MapUtils.getFloat(map, "7");
	
			if(respiratorMap.get(patientId)==null) {
				Map<String,Float> map1 = new HashMap<>(); 
				map1.put(itemCode, itemQuailty);
				respiratorMap.put(patientId,map1);
			}else {
				Map<String,Float> map2 = MapUtils.getMap(respiratorMap, patientId);
				if(map2.get(itemCode)==null) {
					map2.put(itemCode, itemQuailty);
				}else {
					Float oldItemQuality = MapUtils.getFloat(map2, itemCode);
					
					map2.put(itemCode, oldItemQuality+itemQuailty);
				}
				
				respiratorMap.put(patientId,map2);
			}
			
		}
		
		return respiratorMap;
	}
	
	

	@Transactional
	@Override
	public String updateHospiotalManOpscode() {
		List<Map<String, Object>> list = null;
		int onlyCount = 0;
		int emptyCount = 0;
		int multiCount = 0;
		try {
			list = ReadExcelUtil.readExecl("D://手术授权人员汇总表-终(2).xlsx");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(list.size());
		
		
		Map<String,Set<Float>> opsMap = new HashMap<>(); 
		
		List<Float> opList = new ArrayList<>();

		int i = 0;
		int totalCount = 0;
		for (Map<String, Object> map : list) {
		
			//{0=12923, 1=内镜下食管支架取出术, 2=97.59, 3=三, 4=东院消化内科, 5=张春清、史永军、张俊勇、冯华、王广川、张明艳、吴蕾、裴庆山、黄广军、王丽芬}
			Float opsCode = MapUtils.getFloat(map, "2");
			String opsLevel =  MapUtils.getString(map, "3");
			String deptName =  MapUtils.getString(map, "4");
			String doctorName =  MapUtils.getString(map, "5");
			if(opsCode==null) {
				continue;
			}
			
			opList.add(opsCode);
				
			doctorName= doctorName.replaceAll("\\*|\\.|\\，|\\,|\\ |\\  |\\、",",");
			
			List<String> doctorList = Arrays.asList(doctorName.split(","));
			if(CollectionUtils.isEmpty(doctorList)) {
				totalCount++;
			}
			
			Set<Float> doctorSet = null;
			for (String doctor : doctorList) {
				if(StringUtils.isEmpty(doctor)) {
					continue;
				}
				
				
				
				 doctorSet = (Set<Float>) MapUtils.getObject(opsMap, doctor);
				 
				 if(CollectionUtils.isEmpty(doctorSet)) {
					 doctorSet = new HashSet<>();
					 doctorSet.add(opsCode);
					 opsMap.put(doctor, doctorSet);
				 }else {
					 doctorSet.add(opsCode);
					 opsMap.put(doctor, doctorSet);
				 }
			}
			i++;
		}
		
		List<Long> idList = new ArrayList<>();
		List<String> mutiNameList = new ArrayList<>();
		List<String> emptyNameList = new ArrayList<>();
		Set<String> opsCodeSets = new HashSet<>();
		List<StdhospitalmanzyWithBLOBs> stdhospitalmanzyList= new ArrayList<>();
	    for (Map.Entry<String, Set<Float>> m : opsMap.entrySet()) {
	    	Set<Float> opsCodeSet = m.getValue();
	    	StdhospitalmanzyExample example = new StdhospitalmanzyExample();
			
			StdhospitalmanzyExample.Criteria criteria = example.createCriteria();
			criteria.andOrgcodeEqualTo("49557184-0");
			criteria.andStopedflagIsNull();
			criteria.andNameEqualTo(m.getKey());
			List<StdhospitalmanzyWithBLOBs> manList = stdhospitalmanzyMapper.selectByExampleWithBLOBs(example);
			if(CollectionUtils.isNotEmpty(manList)) {
				if(manList.size()==1) {
					onlyCount++;
					StdhospitalmanzyWithBLOBs stdhospitalmanzy = manList.get(0);
					String oldOpsCode = stdhospitalmanzy.getOpsCode();
					Set<String> oldOpsSet =  null;
					if(StringUtils.isEmpty(oldOpsCode)) {
						oldOpsSet = new HashSet<>();
						for(Float opcode:opsCodeSet ) {
							oldOpsSet.add(opcode.toString());
						}
						opsCodeSets.addAll(oldOpsSet);
					}else {
						oldOpsSet = new HashSet<String>(Arrays.asList(oldOpsCode.split(",")));
						for(Float opcode:opsCodeSet ) {
							oldOpsSet.add(opcode.toString());
						}
					
						opsCodeSets.addAll(oldOpsSet);
					}
					
					
					System.out.println(StringUtil.ArrayToString(oldOpsSet.toArray()));
					
					stdhospitalmanzy.setOpsCode(StringUtil.ArrayToString(oldOpsSet.toArray()));
					if(stdhospitalmanzy.getName().equals("李乐平")) {
						stdhospitalmanzyList.add(stdhospitalmanzy);
					}
				
					stdhospitalmanzyMapper.updateByPrimaryKeyWithBLOBs(stdhospitalmanzy);
					
				
					
				}else if(manList.size()>1) {
					multiCount++;
					mutiNameList.add(m.getKey());
				}
			}else {
				emptyCount++;
				emptyNameList.add(m.getKey());
			}
	    }
		
		
	    for (StdhospitalmanzyWithBLOBs stdhospitalmanzyWithBLOBs : stdhospitalmanzyList) {
			System.out.println(stdhospitalmanzyWithBLOBs.getName()+"--"+stdhospitalmanzyWithBLOBs.getOpsCode());
		}

		
		
		
		
		return "根据名字查询:唯一总数="+onlyCount+",多条记录="+multiCount+",记录为空="+emptyCount;
	}
	
	
	
	public List<Map<String,Object>> getOpsCodes(){
		List<Map<String, Object>> list = null;
		try {
			list = ReadExcelUtil.readExecl("D://ops_code.xlsx");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
	}

	
	

	@Transactional
	@Override
	public String addMrTransfusion() {
		int count = 0;
		int pageNumber = Constant.PAGE_NO;
		int pageSize = Constant.PAGE_SIZE;
		int dataLength = pageSize;
		while (dataLength == pageSize) {
			int startIndex = (pageNumber - 1) * pageSize;
		
			List<MrTransfusionObservation> resultList = mrTransfusionObservationMapper.getMrTransfusionObservationPage(startIndex, startIndex + pageSize);

			dataLength = resultList.size();
			count+=dataLength;
			MrTransfusion mrTransfusion = null;
			for (MrTransfusionObservation mrTransfusionObservation : resultList) {
				String componentName = mrTransfusionObservation.getComponentName();
				if(StringUtils.isEmpty(componentName)) {
					continue;
				}
				
				
				mrTransfusion = new MrTransfusion();
				mrTransfusion.setIdCard(mrTransfusionObservation.getIdCard());
				mrTransfusion.setName(mrTransfusionObservation.getName());
				mrTransfusion.setOnlyId(mrTransfusionObservation.getOnlyId());
				mrTransfusion.setMedicalClass(mrTransfusionObservation.getMedicalClass());
				mrTransfusion.setBranchId(mrTransfusionObservation.getBranchId());
				mrTransfusion.setSerialNumber(mrTransfusionObservation.getSerialNumber());
				mrTransfusion.setOrganization(mrTransfusionObservation.getOrganization());
				mrTransfusion.setOrganizationId(mrTransfusionObservation.getOrganizationId());
				mrTransfusion.setRecordNumber(mrTransfusionObservation.getId().toString());
				mrTransfusion.setTransfusionTime(mrTransfusionObservation.getRecordTime());
				mrTransfusion.setRecordTime(new Date());
				//输血类型
				mrTransfusion.setTransfusion("9");
				
//				if(componentName.equals("辐照机采血小板") || componentName.equals("辐照去白机采血小板") || componentName.equals("机采血小板") || componentName.equals("去白机采血小板")) {
//					mrTransfusion.setPlatelet(mrTransfusionObservation.getComponentAmount());
//				}else if(componentName.equals("去白全血")) {
//					mrTransfusion.setWholeBlood(mrTransfusionObservation.getComponentAmount());
//				}else if(componentName.equals("新鲜冰冻血浆") || componentName.equals("病毒灭活血浆") ) {
//					mrTransfusion.setPlasma(mrTransfusionObservation.getComponentAmount());
//				}else if(componentName.equals("悬浮去白红细胞") || componentName.equals("去白洗涤红细胞") || componentName.equals("辐照悬浮去白红细胞") || componentName.equals("辐照去白洗涤红细胞") || componentName.equals("解冻去甘油红细胞")) {
//					mrTransfusion.setRedCell(mrTransfusionObservation.getComponentAmount().intValue());
//				}else if(componentName.equals("自体血")) {
//					mrTransfusion.setAutoblood(mrTransfusionObservation.getComponentAmount().intValue());
//				}else if(componentName.equals("冷沉淀")) {
//					mrTransfusion.setCryo(mrTransfusionObservation.getComponentAmount());
//				}
				
				System.out.println(mrTransfusion);
				
				mrTransfusionMapper.insertSelective(mrTransfusion);
			}
			pageNumber++;
		}
		return "数据总数为:"+count;
	}
	
	
	public static Map<String,String> getHospitalManHisId(){
		Map<String,String> parseData = new HashMap<>();
		List<Map<String, Object>> list;
		try {
			list = ReadExcelUtil.readExecl("D://hisuserid.xlsx");
		
		
		
		for (Map<String, Object> map : list) {
			String jobNumber = MapUtils.getString(map, "1").toUpperCase();
			String hisId = MapUtils.getString(map, "0");
			
			parseData.put(jobNumber, hisId);
		}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return parseData;
	}
	
	
	public static void main(String[] args) throws Exception {
		
		System.out.println(getHospitalManHisId());
		
		
	}
	
	
	
}
